<template>
  <div class="divBox relative">
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <el-tabs v-model="type" @tab-click="getList(1)">
          <el-tab-pane :label="item.name" :name="item.type.toString()" v-for="(item,index) in headeNum" :key="index"/>
        </el-tabs>
        <div class="container">
          <el-form inline size="small" :model="commentFrom" ref="commentFrom" :label-position="labelPosition"  label-width="100px">
            <el-row>
              <el-col :xs="24" :sm="24" :md="24" :lg="18" :xl="18">
                <el-col v-bind="grid">
                  <el-form-item label="受评价者：" style="margin-bottom:0!important;">
                    <el-input v-model="commentFrom.keyword" placeholder="请输入受评价者姓名或公司名称" clearable  class="selWidth"/>
                  </el-form-item>
                </el-col>
              </el-col>
              <el-col  :xs="24" :sm="24" :md="24" :lg="6" :xl="6" class="text-right userFrom">
                <el-form-item style="margin-bottom:0!important;">
                  <el-button label="default" class="" icon="el-icon-search" size="mini" type="primary"  @click="userSearchs">搜索</el-button>
                  <el-button class="ResetSearch mr10" @click="reset('commentFrom')" icon="el-icon-refresh" size="mini">重置</el-button>
                  <a class="ivu-ml-8" @click="collapse = !collapse" hidden>
                    <template v-if="!collapse">
                      展开 <i class="el-icon-arrow-down"></i>
                    </template>
                    <template v-else>
                      收起 <i class="el-icon-arrow-up"></i>
                    </template>
                  </a>
                </el-form-item>
              </el-col>
            </el-row>
          </el-form>
        </div>
      </div>
      <el-table
        ref="table"
        v-loading="listLoading"
        :data="tableData.data"
        style="width: 100%"
        size="mini"
        :header-cell-style=" {fontWeight:'bold',background:'#f8f8f9',color: '#515a6e',height:'40px'}" border
        >
        <el-table-column
          prop="id"
          label="ID"
          min-width="60"
        />
        <el-table-column
          label="评价者"
          min-width="100"
        >
          <template slot-scope="scope">
            <span v-if="[2,3].indexOf(scope.row.type) !== -1">{{scope.row.user.name | filterEmpty  }} | {{scope.row.user.sex | sexFilter}} | {{scope.row.user.type_text | filterEmpty}}</span>
            <span v-else>{{scope.row.user.name | filterEmpty  }}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="受评价者"
          min-width="100"
        >
          <template slot-scope="scope">
            <span v-if="[1].indexOf(scope.row.type) !== -1">{{scope.row.associated.name | filterEmpty  }} | {{scope.row.associated.sex | sexFilter}} | {{scope.row.associated.type_text | filterEmpty}}</span>
            <span v-else>{{scope.row.associated.name | filterEmpty  }}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="涉及零活"
          min-width="100"
        >
          <template slot-scope="scope">
            <span>{{scope.row.work.name | filterEmpty}}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="评分"
          min-width="100"
        >
          <template slot-scope="scope">
            <span>{{scope.row.score | filterEmpty}}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="评论内容"
          min-width="200"
        >
          <template slot-scope="scope">
            <div class="content" :class="{showMore:!scope.row.show}" :title="scope.row.comments">{{scope.row.comments | filterEmpty}}</div>
            <span @click="showMore(scope.row,true)" v-show="!scope.row.show && scope.row.comments" style="color:#0080ff;cursor:pointer;">显示更多</span>
            <span @click="showMore(scope.row,false)" v-show="scope.row.show && scope.row.comments" style="color:#0080ff;cursor:pointer;">收起</span>
          </template>
        </el-table-column>
        </el-table>
      <div class="block">
        <el-pagination
          :page-sizes="[15, 30, 45, 60]"
          :page-size="commentFrom.limit"
          :current-page="commentFrom.page"
          layout="total, sizes, prev, pager, next, jumper"
          :total="tableData.total"
          @size-change="handleSizeChange"
          @current-change="pageChange"
        />
      </div>
    </el-card>
  </div>
</template>

<script>
  import { commentListApi } from '@/api/comment'
  import { checkPermi,checkAdminRole } from "@/utils/permission"; // 权限判断函数
  import {Debounce} from '@/utils/validate'
  export default {
    name: 'CommentIndex',
    components:{ },
    filters: {
      sexFilter(status) {
        const statusMap = {
          0: '未知',
          1: '男',
          2: '女',
        }
        return statusMap[status]
      },
    },
    data() {
      return {
        labelPosition:'right',
        collapse: false,
        loadingBtn: false,
        headeNum: [
          { 'type': '2', 'name': '我发出的' },
          { 'type': '1', 'name': '我收到的' },
        ],
        listLoading: true,
        tableData: {
          data: [],
          total: 0
        },
        type: '2',
        commentFrom: {
          keyword:'',
          page: 1,
          limit: 15,
        },
        grid: {
          xl: 8,
          lg: 12,
          md: 12,
          sm: 24,
          xs: 24
        },
      }
    },
    activated(){
      this.commentFrom.keyword = '';
      if (checkAdminRole()){
        this.type = '3';
      }else{
        this.type = '2';
      }
      this.getList(1);
    },
    mounted() {
      if (checkAdminRole()){
        this.headeNum = [{ 'type': '3', 'name': '所有评价' }]
        this.commentFrom.keyword = '';
        this.type = '3'
      }
      this.getList()
    },
    methods: {
      checkPermi,
      //控制长文本显示和收起
      showMore (row, flag) {
        this.$set(row,'show',flag)
      },

      reset(formName) {
        this.commentFrom = {
            page: 1,
            limit: 15,
            keyword:'',
        }
        this.getList()
      },

      // 搜索
      userSearchs () {
        this.commentFrom.page = 1;
        this.getList();
      },

      // 列表
      getList(num) {
        this.listLoading = true
        this.commentFrom.page = num ? num : this.commentFrom.page;
        this.commentFrom.type = this.type
        commentListApi(this.commentFrom).then(res => {
        //后期接口调用
          this.tableData.data = res.list
          this.tableData.total = res.count
          this.listLoading = false
        }).catch(() => {
          this.listLoading = false
        })
      },

      pageChange(page) {
        this.commentFrom.page = page
        this.getList()
      },
      handleSizeChange(val) {
        this.commentFrom.limit = val
        this.getList()
      },
    }
  }
</script>

<style scoped lang="scss">
  /*.timeBox{*/
  /*width: 100%;*/
  /*::v-deep.el-form-item__content{*/
  /*width: 87% !important;*/
  /*}*/
  /*}*/
  .el-dropdown-link {
    cursor: pointer;
    color: #409EFF;
    font-size: 12px;
  }
  .el-icon-arrow-down {
    font-size: 12px;
  }
  .text-right{
    text-align: right;
  }
  .demo-table-expand {
    font-size: 0;
  }
  .demo-table-expand label {
    width: 90px;
    color: #99a9bf;
  }
  .demo-table-expand .el-form-item {
    margin-right: 0;
    margin-bottom: 0;
    width: 33.33%;
  }
  .selWidth{
    width: 100% !important;
  }
  .seachTiele{
    line-height: 30px;
  }
  .container{
    min-width: 821px;
    ::v-deep.el-form-item{
      width: 100%;
    }
    ::v-deep.el-form-item__content{
      width: 72%;
    }
  }
  .ivu-ml-8{
    font-size: 12px;
    color: #1682e6;
  }
  .btn_bt{
    border-top:1px dashed #ccc;
    padding-top: 20px;
  }
  .relative{
    position: relative;
  }
  .table .showMore{
    display:block;
    width:100%;
    word-break:keep-all;
    white-space:nowrap;
    overflow:hidden;
    text-overflow:ellipsis;
  }
</style>
